/**
 *     This file is part of cesm-ws.
 *
 *     cesm-ws, Web Service for Community Earth System Model
 *
 *     Copyright (c) 2010, Purdue University and/or affilicates or thrid-party contributors as
 *     indicated by the @author tags or express copyright attribution statements
 *     applied by the authors. All third-party contributions are distributed under
 *     license by Purdue University.
 *
 *     cesm-ws is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this distribution.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.purdue.rcac.service.dispatch;

import edu.purdue.rcac.grid.submit.SubmitterResponse;

/**
 * Response bean that each web service receives from {@link ServiceDispatcher}
 * in runtime.
 * 
 * @author Han Zhang
 * 
 */
public class ServiceResponse extends AbstractResponse{


	/**
	 * Action result field
	 */
	private String result;

	/**
	 * Action log field
	 */
	private String log;

	/**
	 * Action error field
	 */
	private String error;

	private String jobDescription;
	private String token;

	public String getJobDescription() {
		return jobDescription;
	}

	public void setJobDescription(String jobDescription) {
		this.jobDescription = jobDescription;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getLog() {
		return log;
	}

	public void setLog(String log) {
		this.log = log;
	}

	public ServiceResponse() {
		this.outcome = Outcome.UNKNOWN;
		this.result = "";
		this.error = "";
		this.token = "";
		this.jobDescription = "";
		this.log = "";
	}
	
	public ServiceResponse(Outcome outcome){
		this();
		this.outcome = outcome;
	}

	public ServiceResponse(SubmitterResponse submitterResponse) {
		this();
		this.error = submitterResponse.getError();
		this.result = submitterResponse.getResult();
		switch (submitterResponse.getOutcome()) {
		case SUCCESS:
			this.outcome = Outcome.SUCCESS;
			break;
		case FAIL:
			this.outcome = Outcome.FAIL;
			break;
		case UNKNOWN:
			this.outcome = Outcome.UNKNOWN;
			break;
		}
		this.jobDescription = submitterResponse.getJobDescription();
		this.log = submitterResponse.getLog();
	}

	public String toString() {
		return String.format("<ServiceResponse>\n" + " outcome: %s\n"
				+ "result: %s\n" + "token: %s\n" + "error: %s\n" + "log: %s",
				this.outcome, this.result, this.token, this.error, this.log);
	}
}
